﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Newtonsoft.Json;

namespace Torch.WL.Business.Interface
{
    public class VerifyInfo<T>
    {
        public UserInfo identication
        {
            get;
            set;
        }

        public T data { get; set; }

        public static string GetIdenticationType(string json)
        {
            string identicationType = "invalidtype";
            string jsonText = json;

            JsonReader reader = new JsonReader(new StringReader(jsonText));

            bool existIdentication = false;

            while (reader.Read())
            {
                if (existIdentication == false && reader.TokenType == JsonToken.PropertyName && compare(reader.Value , "identication"))
                {
                    existIdentication = true;
                    continue;
                }

                if (existIdentication && reader.TokenType == JsonToken.PropertyName && compare(reader.Value , "type"))
                {
                    if (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.String)
                        {
                            identicationType = (reader.Value==null?"":reader.Value.ToString());
                            break;
                        } 
                    } 
                }
            }

            return identicationType;
        }

        private static bool compare(object value , string cmd)
        {
            if (value == null) return false;

            return string.Compare(value.ToString(), cmd, true) == 0; 
        }


    }

    public class UserInfo
    {
        public string type { get; set; }
        public string password { get; set; }
        public string username { get; set; }
        public string imei { get; set; }
        public string info { get; set; }
        public string version { get; set; }
    }


    public class MessageInfo : IMessageInfo
    {
        public int code { get; set; }
        public string message { get; set; }
        public object data { get; set; }        


    }
    



}
